"use strict";
const Constant = require("../basics/constant");
const BaseModel = require("../basics/mysql/mapper");

class HomeModel extends BaseModel {

  constructor(cloud) {
    super(cloud, "mf_dics_v1");
  }

  /**
   * 获取实例
   * @param {*} cloud 
   */
  static getInstant(cloud) {
    return new HomeModel(cloud);
  }

  /**
   * 查询单条
   * @param {string} code 
   */
  async selectOne(code) {
    const ex = this.createExample();
    ex.criteria.andEqual("code", code).andEqual("isuse", Constant.YesOrNo.yes);
    const data = await this.selectOneByExample(ex);
    return data;
  }

  /**
   * 查询单条字符串
   * @param {string} code 
   */
  async selectStrOne(code) {
    const data = await this.selectOne(code);
    if (data) {
      return data.ctxt;
    }
    return null;
  }

  /**
   * 查询单条整数
   * @param {string} code 
   */
  async selectIntOne(code) {
    const data = await this.selectOne(code);
    if (data) {
      return ~~data.ctxt;
    }
    return 0;
  }

}
module.exports = HomeModel;